<template>
	<view class="body">
		<view class="data" v-for="(tiem,index) in classroomData" @click="toClassroomDetail(tiem.id)">
			<view>
				<image src="../../static/img/Python.webp" style="width: 300rpx; height: 200rpx; border-radius: 5%;" mode="scaleToFill"></image>
			</view>
			<view>
				<p style="font-weight: bolder;margin-top: 10rpx;">{{ tiem.title }}</p>
				<p style="margin-top: 50rpx;">上课:{{ tiem.beginTime }}</p>
				<p style="margin-top: 10rpx;">下课:{{ tiem.endTime }}</p>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"classroomList",
		props:['url'],
		data() {
			return {
				classroomData:[],
			};
		},
		methods: {
			async fetchClassroomData() {
				const res = await this.$myRequest({
					url: this.url,
				})
				console.log(res);
				if (res.success) {
					this.classroomData = res.data
					console.log(this.classroomData);
				} else {
					uni.showToast({
						title: "网络出错"
					})
				}
			},
			toClassroomDetail(id) {
				uni.removeStorage({
					key:'classroomId'
				})
				uni.setStorageSync("classroomId",id);
				uni.navigateTo({
					url:"../../pages/classroom/classroomDetail/classroomDetail"
				})
			}
		},
		created() {
			this.fetchClassroomData(); //在实例创建完成后立即调用
		},
	}
</script>

<style lang="scss" scoped>
.body {
	width: 100%;
	height: 200rpx;
	
	.data {
		display: flex;
		
		view {
			margin: 2%;
		} 
	}
}
</style>